/**
 * @param {string} s
 * @param {string[]} dictionary
 * @return {string}
 */
export var findLongestWord = function (s, dictionary) {
  let ans = ''
  function checkInS(w) {
    let i = 0,
      j = 0
    while (i < s.length && j < w.length) {
      if (s[i] === w[j]) {
        j++
      }
      i++
    }
    return j === w.length
  }
  for (const w of dictionary) {
    if (checkInS(w) && (w.length > ans.length || (w.length === ans.length && w < ans))) ans = w
  }
  return ans
}
